package jdbc;

import java.sql.*;

public class TEST {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        String url = "jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf-8&useSSL=true";
        String username = "root";
        String pwd = "123456";

        //1.加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.连接数据库,代表数据库
        Connection connection = DriverManager.getConnection(url,username,pwd);
        //3.向数据库发送sql的对象
        Statement statement = connection.createStatement();

        String sql = "select * from users";
        //执行sql返回结果集
        ResultSet resultSet = statement.executeQuery(sql);

        while(resultSet.next())
        {
            System.out.println("id= " + resultSet.getObject("id"));
            System.out.println("pwd= " + resultSet.getObject("PASSWORD"));
        }

        //关闭连接
        resultSet.close();
        statement.close();
        connection.close();
    }


}
